﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpBolt.Basics;

namespace SharpBolt.Sound
{
    public class SoundSource : SbSoundSource
    {
        public SoundPlayer GetInstance()
        {
            SbSound bsound = Engine.SoundRender.GetEmmitter(this);
            SoundPlayer sound = new SoundPlayer();
            sound.source = this;
            sound.bsound = bsound;
            sound.Pan = 0;
            sound.Volume = .5;
            

            return sound;
        }

        private SoundSource(){}

        private static Dictionary<string, SoundSource> sources;

        public static SoundSource LoadSoundSource(string name)
        {
            if (sources == null) sources = new Dictionary<string, SoundSource>();
            if (sources.ContainsKey(name)) return sources[name];

            SoundSource source = new SoundSource();
            SbSoundSource baseSource = Engine.SoundRender.GetSoundSource(name);
            if (baseSource == null) throw new ArgumentException("OMG no sound file");


            source.data = baseSource.data;
            source.length = baseSource.length;
            source.name = baseSource.name;

            sources.Add(name, source);

            return source;
        }
    }
}
